package com.homedo.odin.solution.enumcode.statistics;

import java.util.Arrays;
import java.util.stream.Collectors;
import lombok.Getter;

/**
 * @author: zhanglei
 * @date: 2018/4/17
 * @Description: 统计相关枚举
 */
@Getter
public enum UserActionBusinessTypeEnum {
    ADVERTISING_SHOW("advertising_show", "广告展示"),
    ADVERTISING_CLICK("advertising_click", "广告点击"),
    CONTACT_US_SHOW("contact_us_show", "查看联系我们"),
    HOT_KEYWORD_CLICK("hot_keyword_click", "热搜关键词点击"),
    COMMON_TYPE_CLICK("common_type_click", "基础数据类型点击"),
    BRAND_CLICK("brand_click", "大牌原厂入口点击"),
    HOT_SOLUTION_CLICK("hot_solution_click", "热搜方案点击"),
    BEST_SOLUTION_CLICK("best_solution_click", "精品方案点击"),
    PRODUCT_DOWNLOAD("product_download", "商品下载");

    private String dbValue;
    private String displayValue;

    UserActionBusinessTypeEnum(String dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }


    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(String dbValue) {
        return Arrays.stream(UserActionBusinessTypeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(UserActionBusinessTypeEnum.values())
                .anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(String dbValue) {
        return Arrays.stream(UserActionBusinessTypeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }

    public static String getDbValues() {
        return Arrays.stream(UserActionBusinessTypeEnum.values()).map(data -> data.getDbValue())
                .collect(Collectors.joining(","));
    }
}
